// 140106-2134;
#pragma once

class LTest
{
public:
	LTest();
	~LTest();
	int mtest;
};
class LObj
{
private: 
	list<LObj *> mcreatlist;
	int linitCreate();
protected:
	void laddCreate( LObj * obj );
	void ldestory();
	virtual int beforeAutoinit(){ return 0; }
public:
	LObj(void);
	virtual ~LObj(void);

	//int lcreate( int state =0);
	int linit( int state =0 );
	//void ldestory( int state =3);

	virtual void setObj( void * obj, int idx );

	static void lexitAll();
protected:
	//virtual int create() { return 0; }
	virtual int init(){ return 0; }
	virtual void exit(){}
	//virtual void afterAutoExit() { }
	virtual void destory() {}

	void lsetClassname( string s ){ mclassname = s; }

	int lautoInitobj( LObj * obj ) { 
		VERIFY( obj );
		int ret = obj->linit();
		//minitlist.push_back( obj ); 
		return ret;
	}
	

	int lnewborn( int & objcnt ) { return ++objcnt; }
	void lnewCheckOne( int & objcnt ) { VERIFY(lnewborn( objcnt) ==1);}
	void lcheckOne( int objcnt ) { VERIFY( objcnt); }

	void lsetMustInit( bool b ) { mlismustinit = b; }

	void lckState( int & state, int hope)	{
		VERIFY ( state == hope );
	}
	void lckStateif( int & state, int hope) {
		if( state == 0 ) // not start;
			return;
		else
			lckState( state, hope);
	}
	void lckStateInc(int & state, int hope) {
		lckState(state, hope);
		state++;
	}
	bool lckStateMulti( int & state, int hope ) {
		if ( state == hope ) { state++; return false; }
		else if( state > hope ) return true;
		else VERIFY(false );
	}
private:
	void laddExitList( LObj * obj );
	void lquitExitList( LObj * qobj );
	void lexit( int state =1 );
	static list<LObj * > mexitlist;
	//static int mtest;
	//static vector<int> mtestvec;
	static LTest mltest;

	string mclassname;

	int mstate;
	bool mlismustinit;

	//int minitcnt;
	//void lincInitcnt() { minitcnt++; }
	//void ldecInitcnt() { if( minitcnt>0) minitcnt--; }

	//vector<LObj *> minitlist;
	//void lautoExitobj();

	int mloopcnt;
	void lincLoopcnt() { mloopcnt++; }
	void ldecLoopcnt() { mloopcnt--; }
	int mexitlpent;
	void lincExitlpent() { mexitlpent++; }
	void ldecExitlpent() { mexitlpent--; }
};


